﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
using System.Data;
using System.Data.SqlClient;
using System.Net.Mail;
using System.Net.Mime;
using System.IO;
using SQLExecute;



public partial class login_get_password : System.Web.UI.Page
{
    public string strMessage;
    public string strFullName;
    public string strUserName;
  
    User u = new User();


    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
           // RandomPassword();
        }
    }
   
    protected bool ValidMail()
    {
        Regex regEmail = new Regex(@"^[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$");
        if (regEmail.IsMatch(txtEmail.Text))
            return true;
        else return false;
    }
    protected void MessageSuccessful()
    {
        strMessage = "Mail sended successful!";
        popupMessage.Show();
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        User u = new User();
        u.Email = txtEmail.Text;
        if (ValidMail())
        {
            if (u.EmailExist())
            {
                u.RandomPassword();
                u.Update_Password();
                u.SendMail("quangtran@vus-etsc.edu.vn", txtEmail.Text, "Nhận lại password!",2);
                MessageSuccessful();
            }
            else
            {
                strMessage = "Địa chỉ email không tồn tại!";
                popupMessage.Show();
            }
        }
        else
        {
            strMessage = "Địa chỉ Email không hợp lệ!";
            popupMessage.Show();
        }

    }
    protected void btnOK_Click(object sender, EventArgs e)
    {
        Response.Redirect("login.aspx");
    }
}
